package com.just.springjpa.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 1.@Entity说明这个class是实体类，并且使用默认的orm规则，即class名即数据库表中表名，class字段名即表中的字段名
 * 如果想改变这种默认的orm规则，就要使用@Table来改变class名与数据库中表名的映射规则，
 * 2.@Column来改变class中字段名与db中表的字段名的映射规则
 */
@Entity
@Table(name = "t_student")
public class Student {
    @Id
    @GeneratedValue
    private Long id;
    /**
     * varchar类型长度50
     */
    @Column(name = "s_name",length = 50)
    private String name;
    /**
     * 不允许为空
     */
    @Column(name="s_age",nullable = false)
    private Integer age;
    /**
     * columnDefinition 创建表时，该字段创建的SQL语句，更灵活的创建表
     */
    @Column(name="created_time",columnDefinition = "datetime  comment '创建时间' ")
    private Date createdTime;
    /**
     * 精度12，小数点后2位
     */
    @Column(name="money",precision = 12,scale = 2)
    private BigDecimal money;

    @JsonIgnore
    @OneToMany(fetch = FetchType.LAZY)
    private List<CourseScore> courseScoreList;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreateTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    public BigDecimal getMoney() {
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    public List<CourseScore> getCourseScoreList() {
        return courseScoreList;
    }

    public void setCourseScoreList(List<CourseScore> courseScoreList) {
        this.courseScoreList = courseScoreList;
    }
}
